package com.ruoyi.change.pay.factory;

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;

import com.basic.service.IBaseService;
import com.ruoyi.change.pay.IPayStatus;
import com.ruoyi.change.pay.impl.AlreadyPay;
import com.ruoyi.change.pay.impl.Unpaid;

public class PayStatusFactory {

	private static Map<Integer, Class<?>> payStatusMap = new HashMap<Integer, Class<?>>(); 
	
	static {
		payStatusMap.put(0, Unpaid.class);
		
		payStatusMap.put(2, AlreadyPay.class);
	}
	
	
	public static  <T extends IPayStatus> void addOperationClass(int type, Class<T> operation) {
		
		payStatusMap.put(type, operation);
	}
	
	/**
	 * 获取处理类
	 * @param <T>
	 * @param <E>
	 * @param type
	 * @param baseService
	 * @return
	 */
	public static  <T extends IPayStatus, E> IPayStatus getOperationClass(int type, IBaseService[] baseService) {
		
		Class<?> target = payStatusMap.get(type);
		
		try {
			
			Constructor<?> constructor = target.getConstructor(baseService.getClass());
			return (IPayStatus) constructor.newInstance(new Object[] {
					baseService
			});
			
		} catch (Exception e) {
			 e.printStackTrace();
			 new Error("找不到处理支付状态的类");
		}
		return null;
		
		
	}
	
	
	
}
